import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.function.Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-06
 * Time: 11:57
 */
public class Test {

    public static void main(String[] args) {
        Set<String> s = new HashSet<>();//无序 不重复、无索引
        //不重复
        Boolean r1 = s.add("张三");
        Boolean r2 = s.add("张三");
        System.out.println(r1);//true
        System.out.println(r2);//false

        s.add("李四");
        s.add("王五");

        //无序
        //System.out.println(s);//[李四, 张三, 王五]

        //迭代器遍历
        Iterator<String> it = s.iterator();
        while (it.hasNext()) {
            String str = it.next();
            System.out.println(str);
        }

        System.out.println("=====");

        //增强for循环遍历
        for (String s1 : s) {
            System.out.println(s1);
        }

        System.out.println("=====");

        //Lambda表达式遍历
        s.forEach(str -> System.out.println(str));
    }
}
